//
//  NSStringExtensions.m
//  MantuPlay
//
//  Created by Markus Sintonen on 9.4.2009.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import "NSStringExtensions.h"

#if TARGET_RT_BIG_ENDIAN
	#define kEncoding NSUTF32BigEndianStringEncoding
#else
	#define kEncoding NSUTF32LittleEndianStringEncoding
#endif

@implementation NSString (NSStringExtensions)

-(int)findCharacter:(char)character {
	for(unsigned int i = 0; i < [self length]; i++) {
		if([self characterAtIndex:i] == character)
			return i;
	}
	return -1;
}
-(int)findCharacterReverse:(char)character {
	for(unsigned int i = ([self length]-1); i > 0; i--) {
		if([self characterAtIndex:i] == character)
			return i;
	}
	return -1;
}

-(NSComparisonResult)compareFirstCharWithAlphabetsHighestOrder:(NSString*)str {
        char char1 = ([self UTF8String])[0];
        char char2 = ([str UTF8String])[0];
        BOOL char1IsAlpha = isalpha(char1);
        BOOL char2IsAlpha = isalpha(char2);
        
        if(char1IsAlpha && char2IsAlpha) {
                goto comp;
        }
        else if(char1IsAlpha) {
                return NSOrderedAscending;
        }
        else if(char2IsAlpha) {
                return NSOrderedDescending;
        }
comp:
        if (char1 < char2)
                return NSOrderedAscending;
        else if (char1 > char2)
                return NSOrderedDescending;
        else
                return NSOrderedSame;
}
@end
